/* 
 * File:   VentanaPrincipal.cpp
 * Author: nahuel
 * 
 * Created on May 20, 2013, 8:24 PM
 */

#include "server_VentanaPrincipal.h"
#include "common_ServerConfFileManager.h"

#include <sstream>
#include <stdlib.h>

void VentanaPrincipal::InitValues() {
    ServerConfFileManager fileManager(_confFileName);
    
    std::string pathAu = fileManager.GetPathAU();
    _pathAu->set_text(pathAu);   
    
    std::string puertoServidor = fileManager.GetPuertoServidor();    
    _puertoServidor->set_text(puertoServidor);
}

VentanaPrincipal::VentanaPrincipal(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& refGlade) 
                    : Gtk::Window(cobject), _builder(refGlade) {
    _confFileName = "config.xml";
    
    _builder->get_widget("EntryPathAU", _pathAu);
    _builder->get_widget("EntryLabelPuertoServidor", _puertoServidor);
    _builder->get_widget("BotonSave", _botonSave);
    
    InitValues();
    
    _botonSave->signal_clicked().connect(sigc::mem_fun(*this, &VentanaPrincipal::onSaveClick));    
    
    show_all_children(true);   
}

void VentanaPrincipal::onSaveClick() {
    std::string pathAu = _pathAu->get_text();    
    std::string puertoServidor = _puertoServidor->get_text();        
    
    ServerConfFileManager fileManager(_confFileName);
    
    fileManager.SetPathAU(pathAu);
    fileManager.SetPuertoServidor(puertoServidor);
    
    fileManager.SaveChanges();   
}

VentanaPrincipal::~VentanaPrincipal() {
    // TODO
}

